package design.p14_templateMethod;

/**
 * @ClassName: Java
 * @description:
 * @author: zxf
 * @create: 2021-06-19 09:58
 **/
public abstract class AbstractCalculator {

    public int[] spilt(String exp,String opt){
        String[] array = exp.split(opt);
        int[] intArray = new int[2];
        intArray[0] = Integer.parseInt(array[0]);
        intArray[1] = Integer.parseInt(array[1]);

        return intArray;
    }

    abstract public int calculator(int num1 ,int num2);

    public final int calculator(String exp,String opt){
        int[] a = this.spilt(exp,opt);
        return calculator(a[0],a[1]);
    }
}
// 把不变的行为搬到超类，子类无需有重复代码

